]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
systemActions: Call into gnome-session for suspend
authorAdrian Vovk <adrianvovk@gmail.com>
Fri, 27 Feb 2026 21:21:46 +0000 (16:21 -0500)
committerMarge Bot <marge-bot@gnome.org>
Tue, 3 Mar 2026 04:57:18 +0000 (04:57 +0000)
gnome-shell previously talked to logind directly on its own. This,
however, will lead to code duplication: the various inhibitor handling
bugfixes I've made to gnome-session (i.e. handling the new return values
from CanPowerOff/CanReboot/CanSuspend) would have to be copied into
gnome-shell. So instead, this commit just moves the responsibility for
handling suspend into gnome-session.

There's a corresponding change in gnome-session

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4040>

data/dbus-interfaces/org.freedesktop.login1.Manager.xml
data/dbus-interfaces/org.gnome.SessionManager.xml
js/misc/loginManager.js
js/misc/systemActions.js

index 7e0fc225e10b95fa106e5226539a5611492a1dc6..acd49acb8a53e7f241e2466c71b5da0b0e85ce55 100644 (file)
@@ -1,11 +1,5 @@
 <node>
   <interface name="org.freedesktop.login1.Manager">
-    <method name="Suspend">
-      <arg type="b" direction="in"/>
-    </method>
-    <method name="CanSuspend">
-      <arg type="s" direction="out"/>
-    </method>
     <method name="Inhibit">
       <arg type="s" direction="in"/>
       <arg type="s" direction="in"/>
index 628a4693b1a9411e5b6cfe676bd77b7dbbf547ed..5c9ef11e31bf6cb0b9ee56e5cd797690478a5735 100644 (file)
@@ -5,12 +5,16 @@
     </method>
     <method name="Shutdown"/>
     <method name="Reboot"/>
+    <method name="Suspend"/>
     <method name="CanShutdown">
       <arg type="u" direction="out"/>
     </method>
     <method name="CanReboot">
       <arg type="u" direction="out"/>
     </method>
+    <method name="CanSuspend">
+      <arg type="u" direction="out"/>
+    </method>
     <method name="IsInhibited">
       <arg type="u" direction="in"/>
       <arg type="b" direction="out"/>
index a66ebed037d602b9064dbb577a73980cc4904971..da989b5b1cb9ad322b0cf7259221f47014506254 100644 (file)
@@ -167,20 +167,6 @@ class LoginManagerSystemd extends Signals.EventEmitter {
         }
     }
 
-    async canSuspend() {
-        let canSuspend, needsAuth;
-
-        try {
-            const [result] = await this._proxy.CanSuspendAsync();
-            needsAuth = result === 'challenge';
-            canSuspend = needsAuth || result === 'yes';
-        } catch {
-            canSuspend = false;
-            needsAuth = false;
-        }
-        return {canSuspend, needsAuth};
-    }
-
     async canRebootToBootLoaderMenu() {
         let canRebootToBootLoaderMenu, needsAuth;
 
@@ -213,10 +199,6 @@ class LoginManagerSystemd extends Signals.EventEmitter {
         return new SystemdLoginSession(Gio.DBus.system, 'org.freedesktop.login1', objectPath);
     }
 
-    suspend() {
-        this._proxy.SuspendAsync(true);
-    }
-
     async inhibit(reason, cancellable) {
         const inVariant = new GLib.Variant('(ssss)',
             ['sleep', 'GNOME Shell', reason, 'delay']);
@@ -268,13 +250,6 @@ class LoginManagerDummy extends Signals.EventEmitter  {
         return new Promise(() => {});
     }
 
-    canSuspend() {
-        return new Promise(resolve => resolve({
-            canSuspend: false,
-            needsAuth: false,
-        }));
-    }
-
     canRebootToBootLoaderMenu() {
         return new Promise(resolve => resolve({
             canRebootToBootLoaderMenu: false,
@@ -293,13 +268,6 @@ class LoginManagerDummy extends Signals.EventEmitter  {
         return null;
     }
 
-    suspend() {
-        this._preparingForSleep = true;
-        this.emit('prepare-for-sleep', true);
-        this._preparingForSleep = false;
-        this.emit('prepare-for-sleep', false);
-    }
-
     get preparingForSleep() {
         return this._preparingForSleep;
     }
index 8147462178fae1bba3e15c45dfbdd265e4de8cfe..db559bfc2ba1f902c2f4489f8686d28ce26a2d51 100644 (file)
@@ -86,6 +86,7 @@ const SystemActions = GObject.registerClass({
         this._canHaveReboot = true;
         this._rebootNeedsAuth = false;
         this._canHaveSuspend = true;
+        this._suspendNeedsAuth = false;
 
         function tokenizeKeywords(keywords) {
             return keywords.split(';').map(keyword => GLib.str_tokenize_and_fold(keyword, null)).flat(2);
@@ -162,7 +163,6 @@ const SystemActions = GObject.registerClass({
         this._screenSaverSettings = new Gio.Settings({schema_id: SCREENSAVER_SCHEMA});
 
         this._session = new GnomeSession.SessionManager();
-        this._loginManager = LoginManager.getLoginManager();
         this._monitorManager = global.backend.get_monitor_manager();
 
         this._userManager = AccountsService.UserManager.get_default();
@@ -397,15 +397,19 @@ const SystemActions = GObject.registerClass({
     }
 
     async _updateHaveSuspend() {
-        const {canSuspend, needsAuth} = await this._loginManager.canSuspend();
-        this._canHaveSuspend = canSuspend;
-        this._suspendNeedsAuth = needsAuth;
+        try {
+            const [availability] = await this._session.CanSuspendAsync();
+            this._canHaveSuspend = availability !== GnomeSession.ActionAvailability.UNAVAILABLE;
+            this._suspendNeedsAuth = availability === GnomeSession.ActionAvailability.CHALLENGE;
+        } catch {
+            this._canHaveSuspend = false;
+            this._suspendNeedsAuth = false;
+        }
         this._updateSuspend();
     }
 
     _updateSuspend() {
-        const disabled = (Main.sessionMode.isLocked &&
-                        this._suspendNeedsAuth) ||
+        const disabled = (Main.sessionMode.isLocked && this._suspendNeedsAuth) ||
                        (Main.sessionMode.isGreeter &&
                         this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
         this._actions.get(SUSPEND_ACTION_ID).available = this._canHaveSuspend && !disabled;
@@ -501,7 +505,7 @@ const SystemActions = GObject.registerClass({
         if (!this._actions.get(SUSPEND_ACTION_ID).available)
             throw new Error('The suspend action is not available!');
 
-        this._loginManager.suspend();
+        this._session.SuspendAsync().catch(logErrorUnlessCancelled);
     }
 
     activateScreenshotUI() {